<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.qbt8.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 千佰特 <http://www.qbt8.com>
// +----------------------------------------------------------------------
namespace plugins\qbt_alisms;
use cmf\lib\Plugin;
use think\Config;
use think\db;

class QbtAlismsPlugin extends Plugin
{

    public $info = [
        'name'        => 'QbtAlisms',
        'title'       => '阿里大鱼',
        'description' => '千佰特手机短信',
        'status'      => 1,
        'author'      => '千佰特',
        'version'     => '1.0',
        'demo_url'    => 'http://www.qbt8.com',
        'author_url'  => 'http://www.qbt8.com',
    ];

    public $hasAdmin = 1;//插件是否有后台管理界面

    // 插件安装
    public function install()
    {
        $config = Config::get('database');
        Db::query("
        CREATE TABLE IF NOT EXISTS `{$config['prefix']}alisms` (
              `id` int(11) NOT NULL AUTO_INCREMENT,
              `config_json` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '配置',
              PRIMARY KEY (`id`) USING BTREE
            ) ENGINE = MyISAM AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
        ");
        Db::query("INSERT INTO `{$config['prefix']}alisms` VALUES (1, '{\"key\":\"\",\"secret\":\"\",\"signName\":\"\",\"tempCode\":\"\"}')");
        Db::query("
        CREATE TABLE IF NOT EXISTS `{$config['prefix']}alisms_log`(
              `id` int(11) NOT NULL AUTO_INCREMENT,
              `phone` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '手机号',
              `code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '验证码',
              `state` tinyint(1) NULL DEFAULT NULL COMMENT '0 未使用\r\n1 使用',
              `create_time` int(10) NULL DEFAULT NULL COMMENT '发送时间',
              PRIMARY KEY (`id`) USING BTREE
            ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
        ");
        return true;
    }

    // 插件卸载
    public function uninstall()
    {
        $config = Config::get('database');
        Db::query("DROP TABLE `{$config['prefix']}alisms`");
        Db::query("DROP TABLE `{$config['prefix']}alisms_log`");
        return true;
    }
}